package com.xjrsoft.module.customerTwo.barin.t_barin_srerp_list.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.common.page.ConventPage;
import java.util.List;
import com.xjrsoft.common.utils.DataTransUtil;
import com.xjrsoft.common.result.Response;
import com.xjrsoft.core.tool.utils.BeanUtil;
import com.xjrsoft.module.customerTwo.barin.t_barin_srerp_list.dto.TBarinSrerpListDto;
import com.xjrsoft.module.customerTwo.barin.t_barin_srerp_list.dto.SaveTBarinSrerpListFormDataDto;
import com.xjrsoft.module.customerTwo.barin.t_barin_srerp_list.vo.TBarinSrerpListVo;
import com.xjrsoft.module.customerTwo.barin.t_barin_srerp_list.vo.TBarinSrerpListListVo;
import com.xjrsoft.module.customerTwo.barin.t_barin_srerp_list.dto.TBarinSrerpListListDto;
import com.xjrsoft.core.secure.utils.SecureUtil;
import com.xjrsoft.core.tool.utils.FlowableUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;

import org.springframework.web.bind.annotation.*;
import com.xjrsoft.module.customerTwo.barin.t_barin_srerp_list.entity.TBarinSrerpList;
import com.xjrsoft.module.customerTwo.barin.t_barin_srerp_list.vo.TBarinSrerpListVo;
import com.xjrsoft.module.customerTwo.barin.t_barin_srerp_list.service.ITBarinSrerpListService;

/**
 *  控制器
 *
 * @author dongxinhang
 * @since 2024-06-18
 */
@RestController
@AllArgsConstructor
@RequestMapping("/t_barin_srerp_list")
@Api(value = "分享版开通清单", tags = "分享版开通清单接口")
public class TBarinSrerpListController {


	private final ITBarinSrerpListService tBarinSrerpListService;


	/**
	 * 详情 
	 */
	@GetMapping("/{id}")
	@ApiOperation(value = "详情", notes = "传入tBarinSrerpList")
	@SaCheckPermission(value = {"t_barin_srerp_list:view", "t_barin_srerp_list:modify"}, mode = SaMode.OR)
	public Response<TBarinSrerpListVo> getFormData(@PathVariable String id) {
		// 主表数据
		TBarinSrerpList tBarinSrerpList = tBarinSrerpListService.getById(id);
		TBarinSrerpListVo tBarinSrerpListVo = BeanUtil.copy(tBarinSrerpList, TBarinSrerpListVo.class);
		return Response.ok(tBarinSrerpListVo);
	}

	/**
	 * 自定义分页 
	 */
	@GetMapping
	@ApiOperation(value = "分页", notes = "传入tBarinSrerpList")
		public Response<PageOutput<TBarinSrerpListListVo>> getPageList(TBarinSrerpListListDto listDto) {
		IPage<TBarinSrerpList> page = tBarinSrerpListService.getPageList(listDto);
		List<TBarinSrerpListListVo> records = BeanUtil.copyList(page.getRecords(), TBarinSrerpListListVo.class);
			// 转换列表数据
		DataTransUtil.transListShowData(records);
			// 工作流数据处理
		FlowableUtil.systemFormList(records, SecureUtil.getModuleId());
		return Response.ok(ConventPage.getPageOutput(page.getTotal(), records));
	}

	/**
	 * 新增 
	 */
	@PostMapping
	@ApiOperation(value = "新增", notes = "传入tBarinSrerpList")
	@SaCheckPermission("t_barin_srerp_list:add")
	public Response save() {
		int count = tBarinSrerpListService.addSrerpData();
		return Response.ok(count);
	}

	/**
	 * 修改 
	 */
	@PutMapping("/{id}")
	@ApiOperation(value = "修改", notes = "传入tBarinSrerpList")
	@SaCheckPermission("t_barin_srerp_list:modify")
	public Response update(@PathVariable String id, @RequestBody SaveTBarinSrerpListFormDataDto formDto) {
		TBarinSrerpListDto tBarinSrerpListDto = formDto.getTBarinSrerpListDto();
		TBarinSrerpList tBarinSrerpList = BeanUtil.copy(tBarinSrerpListDto, TBarinSrerpList.class);
		//修改默认修改为启用
		tBarinSrerpList.setFStatus("1");
		return Response.status(tBarinSrerpListService.updateTBarinSrerpList(id, tBarinSrerpList));
	}



	/**
	 * 删除 
	 */
	@DeleteMapping("/{ids}")
	@ApiOperation(value = "删除", notes = "传入ids")
	@SaCheckPermission(value = {"t_barin_srerp_list:batchDelete", "t_barin_srerp_list:delete"}, mode = SaMode.OR)
	public Response remove(@ApiParam(value = "主键集合", required = true) @PathVariable String ids) {
		return Response.status(tBarinSrerpListService.delete(ids));
	}

	/**
	 * 新增
	 */
	@PostMapping("/updateStatus")
	@ApiOperation(value = "修改", notes = "id，状态")
	public Response updateStatus(@RequestParam("F_Id") String id,@RequestParam("F_Status") String status) {
		TBarinSrerpList one = new TBarinSrerpList();
		one.setFId(id);
		one.setFStatus(status);
		tBarinSrerpListService.updateById(one);
		return Response.ok();
	}
}
